/**
 * StateMachineButton.java
 * Copyright (C) 2009 Jose Mauro da Silva Sandy
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

package utils;

/**
 *
 * @author jmsandy
 */
public class ApplicationPath {

    public ApplicationPath(){

    }

    public static String getApplicationPath(){

        ApplicationPath ap = new ApplicationPath();
        String path = ap.getClass().getResource(
         ap.getClass().getSimpleName() + ".class").toString().split("jar!")[0];
        
        String[] strAux;
        int val = 1;

        if(path.startsWith("jar:file")){
            strAux =
                path.substring(9, path.length()).split(java.io.File.separator);
        }
        else{
            strAux = 
                path.substring(5, path.length()).split(java.io.File.separator);
            val = 2;
        }

        path = "";
        for(int i = 0; i < (strAux.length - val); i++)
            path += strAux[i] + java.io.File.separator;

        try {
            ap.finalize();
        } catch (Throwable ex) {
            ex.printStackTrace();
        }
        return path;
    }

}
